package com.webdiy.hr.action;

import com.sys.plat.util.HttpUtil;
import com.sys.plat.web.core.ActionContext;
import com.sys.plat.web.core.BaseAction;
import com.sys.web.util.SystemUtil;
import com.webdiy.dao.model.HrConfig;
import com.webdiy.hr.form.HrConfigForm;
import com.webdiy.hr.iface.HrConfigSerice;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: mabo
 * Date: 2010-2-9
 * Time: 9:31:57
 * To change this template use File | Settings | File Templates.
 */
public class HrConfigAction extends BaseAction {

    private HrConfigSerice getService() {
        return (HrConfigSerice) getService("HrConfigSericeImpl");
    }

    private HrConfigForm getForm() {
        return (HrConfigForm) ActionContext.getForm();
    }


    public void findListByExt() {
        List list = getService().findList();
        HttpUtil.ListToJSONByModel(list, list.size());
    }


    public void saveByExt() {
        getForm().getHc().setGftUserInfo(SystemUtil.getLoginUser().getGftUserInfo());
        getService().saveOrUpdate(getForm().getHc());
        HttpUtil.printOutToWeb("{success: true , msg: '保存成功'}");
    }


    public void delByExt() {
        getService().delObject(getForm().getIdsToS(), HrConfig.class);
        //HttpUtil.printOutToWeb("{success: true , msg: '删除成功'}");
    }


    /**
     * 抓取数据
     * @return
     */
    public void loadData() {
        Map map;
        if (getForm().getCallPage() != null && getForm().getCallPage().equals("new")) {
            map = new HashMap();
            getService().loadDate(getForm().getHc().getId(), map);
            HttpUtil.sessionSetAttr("loadData", map);
        } else {
            map = (Map) HttpUtil.sessionGetAttr("loadData");

                for (Object o : map.keySet()) {
                    System.out.println(o + " == " + map.get(o));
                }
                System.out.println("");
                System.out.println("");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            
        }
    }


    /**
     * 保存简历
     */
    public void saveJlByExt() {
        getService().saveCoverLetter(getForm().getHc());
        HttpUtil.printOutToWeb("{success: true , msg: '保存成功'}");
    }

    public void findHcClByExt() {
        HttpUtil.printOutToWeb(getService().editHrConfig(getForm().getHc().getId()).getCoverLetter());
    }
}
